let AppUtil={};

import { defineAsyncComponent } from 'vue';

/**
 * 根据view组件路径异步加载组件.
 * @param {String} view 组件路径 这个文件在views 下.
 * @returns {*}
 */
AppUtil.loadComponent=function (view,modules,noDefine){
    if(!view){
        return "";
    }
    if(!modules){
        modules = import.meta.glob('@/views/**/*.vue');
    }
    view = view.includes(".vue")?view : view+".vue";
    let path="/src/views/" +view;
    if(!modules[path]){
        return "";
    }
    return noDefine ? modules[path] : defineAsyncComponent(modules[path]);
}
/**
 * 设置当前语言
 * @param {String} language 语言
 */
AppUtil.setLanguage=function (language){
    localStorage.setItem("language", language);
}

/**
 * 获取当前语言.
 * @returns {string}
 */
AppUtil.getLanguage=function (){
    let language= window.localStorage.getItem("language");
    return language;
}

export default AppUtil;
